home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / ActiveX Controlls / XP Suite / DATA1.CAB / XP_Panel_Sample_Files / Form1.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  2003-04-24  |  34.6 KB  |  979 lines

  1. VERSION 5.00
  2. Object = "{083C8784-F106-4CC2-9930-876218A6B74C}#1.1#0"; "ciaXPButton.ocx"
  3. Object = "{506637F7-8E95-462C-A587-891B4935F57D}#1.0#0"; "ciaXPPanel.ocx"
  4. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  5. Begin VB.Form Form1 
  6.    Caption         =   "Form1"
  7.    ClientHeight    =   7440
  8.    ClientLeft      =   60
  9.    ClientTop       =   450
  10.    ClientWidth     =   10455
  11.    LinkTopic       =   "Form1"
  12.    LockControls    =   -1  'True
  13.    ScaleHeight     =   7440
  14.    ScaleWidth      =   10455
  15.    StartUpPosition =   3  'Windows Default
  16.    Begin VB.PictureBox picICON 
  17.       Appearance      =   0  'Flat
  18.       AutoRedraw      =   -1  'True
  19.       BackColor       =   &H80000005&
  20.       BorderStyle     =   0  'None
  21.       ForeColor       =   &H80000008&
  22.       Height          =   240
  23.       Left            =   10995
  24.       ScaleHeight     =   16
  25.       ScaleMode       =   3  'Pixel
  26.       ScaleWidth      =   16
  27.       TabIndex        =   8
  28.       Top             =   3090
  29.       Visible         =   0   'False
  30.       Width           =   240
  31.    End
  32.    Begin MSComctlLib.StatusBar StatusBar1 
  33.       Align           =   2  'Align Bottom
  34.       Height          =   375
  35.       Left            =   0
  36.       TabIndex        =   7
  37.       Top             =   7065
  38.       Width           =   10455
  39.       _ExtentX        =   18441
  40.       _ExtentY        =   661
  41.       _Version        =   393216
  42.       BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
  43.          NumPanels       =   1
  44.          BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
  45.          EndProperty
  46.       EndProperty
  47.    End
  48.    Begin MSComctlLib.ListView ListView1 
  49.       Height          =   6585
  50.       Left            =   3285
  51.       TabIndex        =   6
  52.       Top             =   540
  53.       Width           =   7155
  54.       _ExtentX        =   12621
  55.       _ExtentY        =   11615
  56.       View            =   3
  57.       LabelWrap       =   -1  'True
  58.       HideSelection   =   -1  'True
  59.       _Version        =   393217
  60.       ForeColor       =   -2147483640
  61.       BackColor       =   -2147483643
  62.       BorderStyle     =   1
  63.       Appearance      =   1
  64.       NumItems        =   0
  65.    End
  66.    Begin ciaXPPanel.XPPanel XPPanel2 
  67.       Align           =   3  'Align Left
  68.       Height          =   6525
  69.       Left            =   0
  70.       TabIndex        =   1
  71.       Top             =   540
  72.       Width           =   3285
  73.       _ExtentX        =   5794
  74.       _ExtentY        =   11509
  75.       LicValid        =   -1  'True
  76.       Begin MSComctlLib.TreeView TreeView1 
  77.          Height          =   6195
  78.          Left            =   0
  79.          TabIndex        =   2
  80.          Top             =   345
  81.          Width           =   3240
  82.          _ExtentX        =   5715
  83.          _ExtentY        =   10927
  84.          _Version        =   393217
  85.          Indentation     =   44
  86.          Style           =   7
  87.          Appearance      =   0
  88.       End
  89.       Begin ciaXPButton.XPButton XPButton1 
  90.          Height          =   255
  91.          Left            =   3015
  92.          TabIndex        =   3
  93.          Top             =   60
  94.          Width           =   210
  95.          _ExtentX        =   370
  96.          _ExtentY        =   450
  97.          Caption         =   "X"
  98.          ButtonStyle     =   2
  99.          OriginalPicSizeW=   0
  100.          OriginalPicSizeH=   0
  101.          BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  102.             Name            =   "MS Sans Serif"
  103.             Size            =   8.25
  104.             Charset         =   0
  105.             Weight          =   700
  106.             Underline       =   0   'False
  107.             Italic          =   0   'False
  108.             Strikethrough   =   0   'False
  109.          EndProperty
  110.          BackStyle       =   0
  111.          LicValid        =   -1  'True
  112.       End
  113.    End
  114.    Begin ciaXPPanel.XPPanel XPPanel1 
  115.       Align           =   1  'Align Top
  116.       Height          =   540
  117.       Left            =   0
  118.       TabIndex        =   0
  119.       Top             =   0
  120.       Width           =   10455
  121.       _ExtentX        =   18441
  122.       _ExtentY        =   953
  123.       LicValid        =   -1  'True
  124.       Begin ciaXPButton.XPButton XPButton2 
  125.          Height          =   480
  126.          Left            =   60
  127.          TabIndex        =   4
  128.          Top             =   15
  129.          Width           =   1080
  130.          _ExtentX        =   1905
  131.          _ExtentY        =   847
  132.          Caption         =   "Folders"
  133.          ButtonStyle     =   2
  134.          Picture         =   "Form1.frx":0000
  135.          PictureWidth    =   22
  136.          PictureHeight   =   20
  137.          PictureSize     =   2
  138.          OriginalPicSizeW=   22
  139.          OriginalPicSizeH=   20
  140.          BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  141.             Name            =   "MS Sans Serif"
  142.             Size            =   8.25
  143.             Charset         =   0
  144.             Weight          =   400
  145.             Underline       =   0   'False
  146.             Italic          =   0   'False
  147.             Strikethrough   =   0   'False
  148.          EndProperty
  149.          Toggle          =   -1  'True
  150.          MaskColor       =   16711935
  151.          BackStyle       =   0
  152.          LicValid        =   -1  'True
  153.       End
  154.       Begin ciaXPButton.XPButton XPButton3 
  155.          Height          =   480
  156.          Left            =   1185
  157.          TabIndex        =   5
  158.          Top             =   15
  159.          Width           =   660
  160.          _ExtentX        =   1164
  161.          _ExtentY        =   847
  162.          Caption         =   ""
  163.          ButtonStyle     =   2
  164.          Picture         =   "Form1.frx":05A2
  165.          PictureWidth    =   23
  166.          PictureHeight   =   19
  167.          PictureSize     =   2
  168.          OriginalPicSizeW=   23
  169.          OriginalPicSizeH=   19
  170.          BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  171.             Name            =   "MS Sans Serif"
  172.             Size            =   8.25
  173.             Charset         =   0
  174.             Weight          =   400
  175.             Underline       =   0   'False
  176.             Italic          =   0   'False
  177.             Strikethrough   =   0   'False
  178.          EndProperty
  179.          BackStyle       =   0
  180.          DropDown        =   -1  'True
  181.          LicValid        =   -1  'True
  182.       End
  183.    End
  184.    Begin MSComctlLib.ImageList ImageList2 
  185.       Left            =   10815
  186.       Top             =   2460
  187.       _ExtentX        =   1005
  188.       _ExtentY        =   1005
  189.       BackColor       =   -2147483643
  190.       ImageWidth      =   16
  191.       ImageHeight     =   16
  192.       MaskColor       =   12632256
  193.       _Version        =   393216
  194.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  195.          NumListImages   =   2
  196.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  197.             Picture         =   "Form1.frx":0B4C
  198.             Key             =   ""
  199.          EndProperty
  200.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  201.             Picture         =   "Form1.frx":4A56
  202.             Key             =   ""
  203.          EndProperty
  204.       EndProperty
  205.    End
  206.    Begin MSComctlLib.ImageList imgSMALL 
  207.       Left            =   10815
  208.       Top             =   1245
  209.       _ExtentX        =   1005
  210.       _ExtentY        =   1005
  211.       BackColor       =   -2147483643
  212.       MaskColor       =   16711935
  213.       _Version        =   393216
  214.    End
  215.    Begin MSComctlLib.ImageList ImageList1 
  216.       Left            =   10800
  217.       Top             =   1830
  218.       _ExtentX        =   1005
  219.       _ExtentY        =   1005
  220.       BackColor       =   -2147483643
  221.       ImageWidth      =   16
  222.       ImageHeight     =   16
  223.       MaskColor       =   16711935
  224.       _Version        =   393216
  225.       BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
  226.          NumListImages   =   17
  227.          BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  228.             Picture         =   "Form1.frx":8208
  229.             Key             =   "hd"
  230.          EndProperty
  231.          BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  232.             Picture         =   "Form1.frx":843A
  233.             Key             =   "dt"
  234.          EndProperty
  235.          BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  236.             Picture         =   "Form1.frx":878C
  237.             Key             =   "ram"
  238.          EndProperty
  239.          BeginProperty ListImage4 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  240.             Picture         =   "Form1.frx":8B60
  241.             Key             =   "mc"
  242.          EndProperty
  243.          BeginProperty ListImage5 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  244.             Picture         =   "Form1.frx":8DF2
  245.             Key             =   "cl"
  246.          EndProperty
  247.          BeginProperty ListImage6 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  248.             Picture         =   "Form1.frx":CCFC
  249.             Key             =   "cd"
  250.          EndProperty
  251.          BeginProperty ListImage7 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  252.             Picture         =   "Form1.frx":D04E
  253.             Key             =   "rte"
  254.          EndProperty
  255.          BeginProperty ListImage8 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  256.             Picture         =   "Form1.frx":D3A2
  257.             Key             =   "f35"
  258.          EndProperty
  259.          BeginProperty ListImage9 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  260.             Picture         =   "Form1.frx":D6C4
  261.             Key             =   "op"
  262.          EndProperty
  263.          BeginProperty ListImage10 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  264.             Picture         =   "Form1.frx":DA18
  265.             Key             =   "new"
  266.          EndProperty
  267.          BeginProperty ListImage11 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  268.             Picture         =   "Form1.frx":DF74
  269.             Key             =   "cab"
  270.          EndProperty
  271.          BeginProperty ListImage12 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  272.             Picture         =   "Form1.frx":E2C8
  273.             Key             =   "zip"
  274.          EndProperty
  275.          BeginProperty ListImage13 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  276.             Picture         =   "Form1.frx":E61C
  277.             Key             =   "rem"
  278.          EndProperty
  279.          BeginProperty ListImage14 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  280.             Picture         =   "Form1.frx":E974
  281.             Key             =   "rar"
  282.          EndProperty
  283.          BeginProperty ListImage15 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  284.             Picture         =   "Form1.frx":ECC8
  285.             Key             =   "md"
  286.          EndProperty
  287.          BeginProperty ListImage16 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  288.             Picture         =   "Form1.frx":F01C
  289.             Key             =   "ace"
  290.          EndProperty
  291.          BeginProperty ListImage17 {2C247F27-8591-11D1-B16A-00C0F0283628} 
  292.             Picture         =   "Form1.frx":F370
  293.             Key             =   "cp"
  294.          EndProperty
  295.       EndProperty
  296.    End
  297. Attribute VB_Name = "Form1"
  298. Attribute VB_GlobalNameSpace = False
  299. Attribute VB_Creatable = False
  300. Attribute VB_PredeclaredId = True
  301. Attribute VB_Exposed = False
  302. Option Explicit
  303. Private Enum LVHITTESTINFO_flags
  304.   LVHT_ONITEMICON = &H2
  305.   LVHT_ONITEMLABEL = &H4
  306.   LVHT_ONITEMINDENT = &H8
  307.   LVHT_ONITEMBUTTON = &H10
  308.   LVHT_ONITEMRIGHT = &H20
  309.   LVHT_ONITEMSTATEICON = &H40
  310.   LVHT_ONITEM = (LVHT_ONITEMICON Or LVHT_ONITEMLABEL Or LVHT_ONITEMSTATEICON)
  311.   ' user-defined
  312.   LVHT_ONITEMLINE = (LVHT_ONITEM Or LVHT_ONITEMINDENT Or LVHT_ONITEMBUTTON Or LVHT_ONITEMRIGHT)
  313. End Enum
  314. Private Type POINTAPI
  315.   x As Long
  316.   y As Long
  317. End Type
  318. Private Type RECT
  319.     Left As Long
  320.     Top As Long
  321.     Right As Long
  322.     Bottom As Long
  323. End Type
  324. Private Type LVHITTESTINFO
  325.   pt As POINTAPI
  326.   flags As LVHITTESTINFO_flags
  327.   hitem As Long
  328. End Type
  329. Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
  330. Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
  331. Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long
  332. Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
  333. Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
  334. Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long
  335. Private Declare Function GetLogicalDrives Lib "kernel32" () As Long
  336. Private Declare Function SHGetFileInfo Lib "shell32.dll" Alias "SHGetFileInfoA" _
  337.            (ByVal pszPath As String, _
  338.             ByVal dwFileAttributes As Long, _
  339.             psfi As SHFILEINFO, _
  340.             ByVal cbSizeFileInfo As Long, _
  341.             ByVal uFlags As Long) As Long
  342. Private Const IMG_SIXTEEN = 16
  343. Private Const IMG_THIRTYTWO = 32
  344. Private Const IMG_ALREADYSET = 0
  345. Private Const IMG_CUSTOM = 1
  346. Private Const icon_FOLDER_CLOSED = 101
  347. Private m_Path As String
  348. Private ArqExt       As String
  349. Private WinDir       As String
  350. Private SysDir       As String
  351. Private TempDir      As String
  352. Private SourcePath   As String
  353. Private sFolder      As String
  354. 'Private sFile        As String
  355. Private sName        As String
  356. Private sExtension   As String
  357. Private sSize        As String
  358. Private sType        As String
  359. Private sModified    As String
  360. Private sTime        As String
  361. Private sCreated     As String
  362. Private sAccessed    As String
  363. Private sAttribute   As String
  364. Private sMsDos       As String
  365. Private sNone        As String
  366. Private m_MyDocs     As String
  367. Private m_hwnd        As Long
  368. '------------------------------
  369. Private Start        As Long
  370. Private FvFilter     As Variant
  371. Private IsFAT        As Boolean
  372. Private InCab        As Boolean
  373. Private InZip        As Boolean
  374. Private Nodx         As Node
  375. Private TypeNew()    As FTs
  376. '------------------------------
  377. Private WithEvents Archive  As cArchive
  378. Attribute Archive.VB_VarHelpID = -1
  379. '------------------------------
  380. Const MyComputer$ = "MyComputer"
  381. Const Desktop$ = "Desktop"
  382. Private Const SHGFI_DISPLAYNAME = &H200
  383. Const m_def_DragDropEnable = 0
  384. Const m_def_FileFilter = "*.ace;*.cab;*.rar;*.zip"
  385. Const m_def_hWnd = 0
  386. Const m_def_Path$ = ""
  387. Private m_DragDropEnable As Boolean
  388. Private m_FileFilter As String
  389. Private m_hwndTV As Long
  390. Private Sub AddImage(resICONVAL As Long, Optional imgSIZE As Long = IMG_ALREADYSET, Optional CustomHeight As Long = 16, Optional CustomWidth As Long = 16)
  391.     On Error Resume Next
  392.     With imgSMALL
  393.         If imgSIZE <> IMG_ALREADYSET Then
  394.             If imgSIZE <> IMG_CUSTOM Then
  395.                 .ImageHeight = imgSIZE
  396.                 .ImageWidth = imgSIZE
  397.             Else
  398.                 .ImageHeight = CustomHeight
  399.                 .ImageWidth = CustomWidth
  400.             End If
  401.         End If
  402.         .ListImages.Add , , LoadResPicture(resICONVAL, vbResBitmap)
  403.     End With
  404. End Sub
  405. Private Sub ChangeImageSize(imgSIZE As Long, Optional CustomHeight As Long = 16, Optional CustomWidth As Long = 16)
  406.     On Error Resume Next
  407.     With imgSMALL
  408.         If imgSIZE <> IMG_ALREADYSET Then
  409.             If imgSIZE <> IMG_CUSTOM Then
  410.                 .ImageHeight = imgSIZE
  411.                 .ImageWidth = imgSIZE
  412.             Else
  413.                 .ImageHeight = CustomHeight
  414.                 .ImageWidth = CustomHeight
  415.             End If
  416.         End If
  417.     End With
  418. End Sub
  419. Private Sub SetPath(New_Path As String)
  420.     While Right(New_Path, 1) = "\"
  421.         New_Path = Left(New_Path, Len(New_Path) - 1)
  422.     Wend
  423.     If New_Path <> "" Then
  424.         m_Path = New_Path
  425.     Else
  426.         XPListView1.ListItems.Clear
  427.     End If
  428. End Sub
  429. Private Sub FillFiles()
  430.     On Error GoTo ErrorFillFiles
  431.     Dim obj As Scripting.FileSystemObject, f As Scripting.Folder, i As Scripting.File
  432.     Dim sf As Scripting.Folder, itm As ListItem, iIMG As CICON, x As Long
  433.     FreezeWindow ListView1.hwnd
  434.     ListView1.ListItems.Clear
  435.     ListView1.ColumnHeaders.Clear
  436.     ListView1.ColumnHeaders.Add , , "Please wait...", 1440
  437.     ListView1.ListItems.Add , , "Loading..."
  438.     FreezeWindow
  439.     ListView1.Refresh
  440.     DoEvents
  441.     FreezeWindow ListView1.hwnd
  442.     ListView1.ListItems.Clear
  443.     ListView1.ColumnHeaders.Clear
  444.     ListView1.ColumnHeaders.Add , , "NAME"
  445.     ListView1.ColumnHeaders.Add , , "SIZE"
  446.     ListView1.ColumnHeaders.Add , , "TYPE"
  447.     ListView1.ColumnHeaders.Add , , "MODIFIED"
  448.     Set ListView1.SmallIcons = Nothing
  449.     imgSMALL.ListImages.Clear
  450.     AddImage icon_FOLDER_CLOSED, IMG_SIXTEEN
  451.     Set obj = New Scripting.FileSystemObject
  452.     Set f = obj.GetFolder(m_Path)
  453.     For Each i In f.Files
  454.         Set iIMG = New CICON
  455.         picICON.Picture = LoadPicture()
  456.         iIMG.ExtractIconToHDC picICON.hdc, m_Path & "\" & i.Name
  457.         Set iIMG = Nothing
  458.         picICON.Picture = picICON.Image
  459.         imgSMALL.ListImages.Add , , picICON.Picture
  460.         picICON.Picture = LoadPicture()
  461.     Next
  462.     Set ListView1.SmallIcons = imgSMALL
  463.     For Each sf In f.SubFolders
  464.         Set itm = ListView1.ListItems.Add(, , sf.Name, , 1)
  465.         itm.SubItems(2) = sf.Type
  466.         itm.SubItems(3) = sf.DateLastModified
  467.         itm.Tag = "FOLDER"
  468.     Next
  469.     x = 2
  470.     For Each i In f.Files
  471.         Set itm = ListView1.ListItems.Add(, , i.Name, , x)
  472.         x = x + 1
  473.         itm.SubItems(1) = i.Size
  474.         itm.SubItems(2) = i.Type
  475.         itm.SubItems(3) = i.DateLastModified
  476.         itm.Tag = "FILE"
  477.     Next
  478.     FreezeWindow
  479.     Exit Sub
  480. ErrorFillFiles:
  481.     FreezeWindow
  482.     MsgBox Err & ":Error in FillFiles.  Error Message: " & Err.Description, vbCritical, "Warning"
  483.     Exit Sub
  484. End Sub
  485. Private Function FreezeWindow(Optional mLNGhWnd As Long = 0) As Long
  486.     On Error Resume Next
  487.     Dim x As Long
  488.     FreezeWindow = LockWindowUpdate(mLNGhWnd)
  489. End Function
  490. Private Sub Form_Activate()
  491. FillFiles
  492. End Sub
  493. Private Sub Form_Load()
  494. m_Path = "C:"
  495. InitializeTree
  496. Const Shell32$ = "Shell32.Dll"
  497. FvFilter = Split(LCase(m_FileFilter), ";")
  498. m_MyDocs = FolderLocation(CSIDL_PERSONAL)
  499. 'Get Win, Sys, & Temp directory paths
  500. WinDir = Left$(Buffer, GetWindowsDirectory(Buffer, MAX_PATH))
  501. SysDir = Left$(Buffer, GetSystemDirectory(Buffer, MAX_PATH))
  502. TempDir = Left$(Buffer, GetTempPath(MAX_PATH, Buffer))
  503. sFolder = GetResourceStringFromFile(Shell32, 4131) '"(" & GetResourceStringFromFile(Shell32, 4131) & ")"
  504. sName = GetResourceStringFromFile(Shell32, 8976)
  505. sExtension = StrConv(ext_, vbProperCase)
  506. sSize = GetResourceStringFromFile(Shell32, 8978)
  507. sType = GetResourceStringFromFile(Shell32, 8979)
  508. sModified = GetResourceStringFromFile(Shell32, 8980)
  509. sTime = GetResourceStringFromFile("Intl.Cpl", 25)
  510. sCreated = GetResourceStringFromFile(Shell32, 8996)
  511. sAccessed = GetResourceStringFromFile(Shell32, 8997)
  512. sAttribute = GetResourceStringFromFile(Shell32, 8987)
  513. sMsDos = "MsDos 8.3"
  514. sNone = GetResourceStringFromFile(Shell32, 9808)
  515. Enumerate
  516. 'LVColumnHeaders
  517. ListView1.Visible = True
  518. ListView1.Refresh
  519. ReDim Preserve TypeNew(0) 'init array of Ext/Type/IconIdx
  520. End Sub
  521. Private Sub InitializeTree()
  522. TreeView1.ImageList = ImageList1
  523. End Sub
  524. '******************************************************* TreeView Code *************************************************
  525. Private Function BuildFullPath(ByVal Nod As Node) As String
  526. On Error GoTo PROC_ERR
  527. Dim iPos As Integer
  528. Dim sExt As String
  529. Dim MyPath As String
  530. Dim MyDocs2 As String
  531. MyPath = Nod.FullPath
  532. iPos = InStrRev(MyPath, ":")
  533. If iPos < 2 Then
  534.     MyDocs2 = Mid(m_MyDocs, 4)
  535.     BuildFullPath = Replace(MyPath, Desktop & "\" & MyDocs2, m_MyDocs)
  536.     GoTo CheckExt
  537. End If
  538. MyPath = Mid$(MyPath, iPos - 1) 'Pick up drive letter
  539. iPos = InStr(MyPath, "\")
  540. If iPos > 1 Then
  541.     BuildFullPath = Left$(MyPath, 2) & Mid$(MyPath, iPos)
  542.     BuildFullPath = Left$(MyPath, 2)
  543. End If
  544. CheckExt:
  545. sExt = GetExt(Nod.Text)
  546. If sExt <> "" Then
  547.     For iPos = 0 To UBound(FvFilter)
  548.         If sExt = GetExt(FvFilter(iPos)) Then 'Match
  549.             Exit Function
  550.         End If
  551.     Next
  552. End If
  553. BuildFullPath = QualifyPath(BuildFullPath)
  554. PROC_EXIT:
  555. Exit Function
  556. PROC_ERR:
  557. If ErrMsgBox("BuildFullPath") = vbRetry Then Resume Next
  558. End Function
  559. Private Sub ClearTree()
  560.     TreeView1.Visible = False
  561.     TreeView1.Nodes.Clear
  562.     TreeView1.Visible = True
  563. End Sub
  564. Private Sub LoadTree()
  565.    Const Shell32$ = "Shell32.Dll"
  566.    On Error GoTo PROC_ERR
  567.    'Use API (MUCH faster than scripting)
  568. '------------------------------
  569.    Dim FirstFixed  As Integer
  570.    Dim MaxPwr      As Integer
  571.    Dim Pwr         As Integer
  572. '------------------------------
  573.    Dim DrvBitMask  As Long
  574.    Dim DriveType   As Long
  575. '------------------------------
  576.    Dim MyDrive     As String
  577.    Dim MyPic       As String
  578.    Dim MyKey       As String
  579. '------------------------------
  580.    Dim nod1        As Node
  581.    Dim si          As SHFILEINFO
  582.    Dim RC          As RECT
  583. '------------------------------
  584.    TreeView1.ImageList = ImageList1    ' Initialize ImageList.
  585.    m_hwndTV = TreeView1.hwnd
  586.   ' Establish the distance in which auto-scrolling happens within
  587.   ' the TreeView's client area (we need a root item for these calls)
  588. '  If TreeView_GetItemRect(m_hwndTV, TreeView_GetRoot(m_hwndTV), RC, True) Then
  589. '    m_cxyAutoScroll = (RC.Bottom - RC.Top) * 2
  590. '  Else
  591. '    m_cxyAutoScroll = 32
  592. '  End If
  593.   ' Initialize the auto expand and auto scroll timers
  594.   ' already set in design properties
  595.   ' tmrAutoExpand.Enabled = False
  596.   ' tmrAutoExpand.Interval = 1000
  597.   ' tmrAutoScroll.Enabled = False
  598.   ' tmrAutoScroll.Interval = 100
  599.   ' Store thet distance the cursor moves to initiate dragging.
  600. '  m_szDrag.cx = GetSystemMetrics(SM_CXDRAG)
  601. '  m_szDrag.cy = GetSystemMetrics(SM_CYDRAG)
  602. 'Private Const DRIVE_UNKNOWN       As Long = 0
  603. 'Private Const DRIVE_NO_ROOT_DIR   As Long = 1
  604. 'Private Const DRIVE_REMOVABLE     As Long = 2
  605. 'Private Const DRIVE_FIXED         As Long = 3
  606. 'Private Const DRIVE_REMOTE        As Long = 4
  607. 'Private Const DRIVE_CDROM         As Long = 5
  608. 'Private Const DRIVE_RAMDISK       As Long = 6
  609.    MyDrive = GetResourceStringFromFile(Shell32, 4162) 'Desktop
  610.    Set nod1 = TreeView1.Nodes.Add(, , Desktop, MyDrive, "dt")
  611.    '-----
  612.    'MyDrive = GetResourceStringFromFile(Shell32, 9100) 'My Documents
  613.    m_MyDocs = FolderLocation(CSIDL_PERSONAL)
  614.    Set nod1 = TreeView1.Nodes.Add(Desktop, tvwChild, QualifyPath(m_MyDocs), Mid(m_MyDocs, 4), "md")
  615.    If hasSubDirectory(m_MyDocs) Then
  616.       TreeView1.Nodes.Add nod1, tvwChild
  617.    End If
  618.    '-----
  619.    Set nod1 = TreeView1.Nodes.Add(Desktop, tvwChild, "Ftp", "Ftp Client", "rte")
  620.    '-----
  621.    MyDrive = GetResourceStringFromFile(Shell32, 9216) 'My Computer
  622.    Set nod1 = TreeView1.Nodes.Add(Desktop, tvwChild, MyComputer, MyDrive, "mc")
  623.    '-----
  624.    DrvBitMask = GetLogicalDrives()
  625.    ' DrvBitMask is a bitmask representing
  626.    ' available disk drives. Bit position 0
  627.    ' is drive A, bit position 2 is drive C, etc.
  628.    ' If function fails, return value is zero.
  629.    If DrvBitMask Then
  630.     ' Get & search each available drive
  631.       MaxPwr = Int(Log(DrvBitMask) / Log(2))   ' a little math...
  632.       For Pwr = 0 To MaxPwr
  633.          If 2 ^ Pwr And DrvBitMask Then
  634.             MyDrive = Chr$(65 + Pwr) & ":\"
  635.             DriveType = GetDriveType(MyDrive)
  636.             Select Case DriveType
  637.                Case 0, 1: MyPic = "dl"
  638.                Case 2:
  639.                   If Pwr < 2 Then 'A or B (Diskette)
  640.                      MyPic = "f35"
  641.                   Else 'other Removable
  642.                      MyPic = "rem"
  643.                   End If
  644.                Case 3: MyPic = "hd"
  645.                Case 4: MyPic = "rte"
  646.                Case 5: MyPic = "cd"
  647.                Case 6: MyPic = "ram"
  648.             End Select
  649.             'Get Drive DisplayName.
  650.             SHGetFileInfo MyDrive, 0&, si, Len(si), SHGFI_DISPLAYNAME
  651.             Set nod1 = TreeView1.Nodes.Add(MyComputer, tvwChild, MyDrive, si.szDisplayName, MyPic)
  652.             If (FirstFixed = 0) And (DriveType = 3) Then
  653.                FirstFixed = TreeView1.Nodes.Count
  654.             End If
  655.             TreeView1.Nodes.Add nod1, tvwChild
  656.          End If
  657.       Next
  658.    End If
  659.    'Add Control Panel
  660.    MyDrive = GetResourceStringFromFile(Shell32, 4161)
  661.    Set nod1 = TreeView1.Nodes.Add(MyComputer, tvwChild, "ControlPanel", MyDrive, "cp")
  662.    TreeView1.Nodes.Add nod1, tvwChild
  663.    'expand first fixed drive
  664.    Set nod1 = TreeView1.Nodes(FirstFixed)
  665.    nod1.Expanded = True
  666.    nod1.EnsureVisible
  667.    'ensure first entry (Desktop) is visible
  668.    Set nod1 = TreeView1.Nodes(1) 'Desktop
  669.    nod1.EnsureVisible
  670.    TreeView1.Refresh
  671.    Set nod1 = Nothing
  672. PROC_EXIT:
  673.   Exit Sub
  674. PROC_ERR:
  675.   If ErrMsgBox("LoadTree6") = vbRetry Then Resume Next
  676. End Sub
  677. Private Sub SetNodeVisible()
  678. Dim L4 As Long, Nod As Node
  679. Dim sFullPath As String
  680. Dim qPath As String
  681. qPath = QualifyPath(m_Path)
  682. For L4 = 1 To TreeView1.Nodes.Count
  683.     Set Nod = TreeView1.Nodes(L4)
  684.     sFullPath = BuildFullPath(Nod)
  685.     If StrComp(sFullPath, qPath, vbTextCompare) = 0 Then
  686.         Nod.EnsureVisible
  687.         Nod.Selected = True
  688.         TreeView1.Refresh
  689.         Exit For
  690.     End If
  691. End Sub
  692. Private Sub Enumerate()
  693.    ClearTree
  694.    FvFilter = Split(m_FileFilter, ";")
  695.    LoadTree
  696. End Sub
  697. Private Function FileExistsW32FD(sSource As String) As WIN32_FIND_DATA
  698. Dim hFile As Long
  699. 'Returns True in dwReserved1 if file exists as well as raw data in WIN32_FIND_DATA structure
  700. hFile = FindFirstFile(sSource, FileExistsW32FD)
  701. FileExistsW32FD.dwReserved1 = hFile <> INVALID_HANDLE_VALUE
  702. FindClose hFile
  703. End Function
  704. Private Sub EnumFilesUnder(ByVal n As Node)
  705. On Error GoTo PROC_ERR
  706. Dim sPath As String
  707. Dim sExt As String
  708. Dim hFind As Long, L4 As Long
  709. Dim oldPath As String
  710. Dim W32FD As WIN32_FIND_DATA
  711. Dim n2 As Node
  712. Dim FolderPic As String
  713. TreeView1.Visible = False
  714. oldPath = ""
  715. sPath = BuildFullPath(n) & "*.*"
  716. 'old sPath = ucase$(n.FullPath & "\*.*")
  717. hFind = FindFirstFile(sPath, W32FD)
  718.     ' Get the filename, if any.
  719.     sPath = StripNull(W32FD.cFileName)
  720.     If Len(sPath) = 0 Or StrComp(sPath, oldPath) = 0 Then
  721.         ' Nothing found?
  722.         Exit Do
  723.     ElseIf Asc(sPath) <> 46 Then
  724.        'do we have a folder?
  725.        If (W32FD.dwFileAttributes And vbDirectory) Then 'Yes
  726.            FolderPic = "cl"
  727.            Set n2 = TreeView1.Nodes.Add(n, tvwChild, , sPath, FolderPic)
  728.            n2.ExpandedImage = "op"
  729.            'causes duplicate keys in My Documents n2.Key = BuildFullPath(n2)
  730.            ' Add a dummy item so the + sign is displayed
  731.             If hasSubDirectory(BuildFullPath(n) & sPath & "\") Then
  732.                 TreeView1.Nodes.Add n2, tvwChild
  733.             End If
  734.        Else  'do we have a matching file?
  735.             sExt = GetExt(sPath)
  736.             For L4 = 0 To UBound(FvFilter)
  737.                 If sPath Like FvFilter(L4) Then 'Yes
  738.                     Select Case sExt
  739.                         Case "zip", "cab", "ace", "rar"
  740.                             FolderPic = sExt
  741.                         Case Else
  742.                             FolderPic = "new"
  743.                     End Select
  744.                   Set n2 = TreeView1.Nodes.Add(n, tvwChild, , sPath, FolderPic)
  745.                   'n2.Key = BuildFullPath(n2)
  746.                   ' TV.Nodes.Item(TV.Nodes.Count).Bold = True
  747.                   '***Node colors don't work if you are using background (wallpaper) in Treeview
  748.                   TreeView1.Nodes.Item(TreeView1.Nodes.Count).BackColor = vbBlue '&H98CCD0   '&HE0E0E0    'grey
  749.                   TreeView1.Nodes.Item(TreeView1.Nodes.Count).ForeColor = vbWhite    'RGB(248, 240, 136) 'Tree ylw
  750.                   Exit For
  751.                End If
  752.             Next
  753.        End If
  754.     End If
  755.     FindNextFile hFind, W32FD
  756.     oldPath = sPath
  757. FindClose hFind
  758. TreeView1.Visible = True
  759. Exit Sub
  760. PROC_EXIT:
  761. Exit Sub
  762. PROC_ERR:
  763. If ErrMsgBox("EnumFilesUnder") = vbRetry Then Resume Next
  764. End Sub
  765. Private Function GetExt(ByVal Name As String) As String
  766. On Error GoTo PROC_ERR
  767. Dim J As Integer
  768. J = InStrRev(Name, ".")
  769. If J > 0 And J < Len(Name) Then
  770.     GetExt = LCase$(Mid$(Name, J + 1))
  771. End If
  772. PROC_EXIT:
  773. Exit Function
  774. PROC_ERR:
  775. If ErrMsgBox("GetExt") = vbRetry Then Resume Next
  776. End Function
  777. Private Function hasSubDirectory(ByVal sPath As String) As Boolean
  778. On Error GoTo PROC_ERR
  779. Dim hFind As Long
  780. Dim oldPath As String
  781. Dim W32FD As WIN32_FIND_DATA
  782. Dim L4 As Long
  783. oldPath = ""
  784. hFind = FindFirstFile(sPath & "*.*", W32FD)
  785.     ' Get the filename, if any.
  786.     sPath = StripNull(W32FD.cFileName)
  787.     If Len(sPath) = 0 Or StrComp(sPath, oldPath) = 0 Then
  788.         ' Nothing found?
  789.         Exit Do
  790.     ElseIf Asc(sPath) <> 46 Then
  791.         ' return true if we have found a directory under this path
  792.         If (W32FD.dwFileAttributes And vbDirectory) Then
  793.             hasSubDirectory = True
  794.             Exit Do
  795.         End If
  796.         For L4 = 0 To UBound(FvFilter)
  797.             If sPath Like FvFilter(L4) Then
  798.                 hasSubDirectory = True
  799.                 Exit Do
  800.             End If
  801.         Next
  802.     End If
  803.     FindNextFile hFind, W32FD
  804.     oldPath = sPath
  805. FindClose hFind
  806. PROC_EXIT:
  807. Exit Function
  808. PROC_ERR:
  809. If ErrMsgBox("hasSubDirectory") = vbRetry Then Resume Next
  810. End Function
  811. Private Sub LoadFiles(ByVal Path As String)
  812.        
  813. On Error GoTo ProcedureError
  814. Dim Win32Fd As WIN32_FIND_DATA
  815. Dim lHandle As Long
  816. Dim Item As ListItem
  817. Dim MyName As String
  818. Dim sExt As String
  819. Dim MyDate As Date
  820. Dim MySize As Currency
  821. Dim MyIcon As Long
  822. Dim Start As Long
  823. Dim MyCount As Long
  824. Const MustGet$ = "exe|ico|lnk|pif|cur"
  825. Start = GetTickCount()
  826. Screen.MousePointer = vbHourglass
  827. InZip = False
  828. SourcePath = QualifyPath(Path)
  829. 'LVColumnHeaders
  830. 'IsFAT = CheckFAT
  831. lHandle = FindFirstFile(SourcePath & "*.*", Win32Fd)
  832. If lHandle > 0 Then
  833. End If
  834. FindClose lHandle
  835. 'LoadCleanup 3
  836. 'ShowProgress Start, MyCount, Path
  837. ProcedureExit:
  838. Exit Sub
  839. ProcedureError:
  840. If ErrMsgBox(Me.Name & ".LoadFiles") = vbRetry Then Resume Next
  841. End Sub
  842. Private Sub ShowProgress(Start, Count, Path)
  843.    Me.Caption = Format((GetTickCount() - Start) / 1000, "#,##0.00") & " seconds, " & Count & " Objects in " & Path
  844. End Sub
  845. Private Function GetFileType(ByVal sExt As String, ByVal FullPath As String, ByRef MyIcon As Long) As String
  846. On Error GoTo ProcedureError
  847. Dim sName As String
  848. Dim lRegKey As Long, L4 As Long
  849. If sExt <> "" Then
  850.     'NOTE: Array must be sorted for binary search
  851.     L4 = BinarySearchTypeNew(sExt)
  852.     If L4 <> -1 Then
  853.         GetFileType = TypeNew(L4).Type
  854.         MyIcon = TypeNew(L4).IconIndex
  855.         Exit Function
  856.     End If
  857.     'Not a duplicate so get info from registry
  858.     If RegOpenKey(HKEY_CLASSES_ROOT, ByVal "." & sExt, lRegKey) = 0 Then
  859.         'Get type of file (Not to be confused with actual FileType )
  860.         RegQueryValueEx lRegKey, ByVal "", 0&, 1, ByVal Buffer, MAX_PATH
  861.         sName = StripNull(Buffer)
  862.         RegCloseKey lRegKey
  863.         If Len(sName) Then
  864.             'Get FileType
  865.             If RegOpenKey(HKEY_CLASSES_ROOT, sName, lRegKey) = 0 Then
  866.                 RegQueryValueEx lRegKey, ByVal "", 0&, 1, ByVal f_Type, 80
  867.                 GetFileType = StripNull(f_Type)
  868.                 RegCloseKey lRegKey
  869.             End If
  870.         End If
  871.     End If
  872.     'Bump array and add new extension/type
  873.     L4 = UBound(TypeNew()) + 1
  874.     ReDim Preserve TypeNew(L4)
  875.     TypeNew(L4).Ext = sExt
  876.     If GetFileType = "" Then 'No associated type
  877.         GetFileType = sNone 'was sFile & " " & UCase$(sExt)
  878.         TypeNew(L4).IconIndex = 0
  879.     Else 'New Ext, get this Icon
  880.         SHGetFileInfo FullPath, 0&, SFI, cbSFI, SMALLSYS_SHGFI_FLAGS
  881.         TypeNew(L4).IconIndex = SFI.iIcon  'index in system imagelist
  882.     End If
  883.     TypeNew(L4).Type = GetFileType
  884.     MyIcon = TypeNew(L4).IconIndex
  885.     ShellSortTypeNewArray 'So we can use a binary search
  886. End If
  887. ProcedureExit:
  888. Exit Function
  889. ProcedureError:
  890. If ErrMsgBox(Me.Name & ".GetFileType") = vbRetry Then Resume Next
  891. End Function
  892. Private Sub ListView1_DblClick()
  893. On Error Resume Next
  894. Dim pt As POINTAPI
  895. Dim itm As ListItem
  896. GetCursorPos pt
  897. Set itm = ListView1.HitTest(pt.x, pt.y)
  898. If itm.Tag = "FOLDER" Then 'itFOLDER Then
  899.   '  m_Path = SetPath(m_Path) & "\" & itm.Text
  900.     m_Path = m_Path & "\" & itm.Text
  901.     Debug.Print "m_Path = " & m_Path & "| itm.Text = " & itm.Text
  902.     FillFiles
  903. End If
  904. Set itm = Nothing
  905. End Sub
  906. '**************************************************** TREEVIEW EVENTS *********************************************
  907. Private Sub TreeView1_Expand(ByVal Node As MSComctlLib.Node)
  908. ' RaiseEvent Expand(Node)
  909. On Error GoTo PROC_ERR
  910. Screen.MousePointer = vbHourglass
  911. If Node.Children = 1 And Node.Child.Children <= 0 Then
  912.     ' Remove the "dummy" item
  913.     TreeView1.Nodes.Remove Node.Child.Index
  914.     ' Enumerate file system items under this node
  915.     Node.Sorted = False
  916.     EnumFilesUnder Node
  917.     Node.Sorted = True
  918. End If
  919. Screen.MousePointer = vbDefault
  920. PROC_EXIT:
  921. Exit Sub
  922. PROC_ERR:
  923. If ErrMsgBox("TV_Expand") = vbRetry Then Resume Next
  924. End Sub
  925. Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
  926. On Error GoTo FolderView1_NodeClick_Err
  927. Dim Path As String, sExt As String
  928. Dim Start As Long
  929. Set Nodx = Node
  930. ReDim Preserve TypeNew(0)
  931. Select Case Node.Key
  932.     Case "Ftp"
  933.         ListView1.ListItems.Clear
  934.     Case "Desktop"
  935.         LoadFiles QualifyPath(FolderLocation(CSIDL_DESKTOP))
  936.     Case "MyComputer"
  937.       
  938.     Case "MyDocuments"
  939.         LoadFiles QualifyPath(FolderLocation(CSIDL_PERSONAL))
  940.     Case "ControlPanel"
  941.         Shell "rundll32.exe shell32.dll,Control_RunDLL", vbNormalFocus
  942.     Case Else
  943.         Path = BuildFullPath(Node)
  944.         sExt = GetExt(Node.Text)
  945.         Start = GetTickCount()
  946.    '     ShowTip = True
  947.         Select Case sExt
  948.             Case ace_, cab_, rar_, zip_
  949.                 SourcePath = Path
  950.                 InZip = True
  951.          '       Tip.MouseNotify FolderView1.hwnd, tipMouseMove
  952.                    'LoadStart
  953.                 Screen.MousePointer = vbHourglass
  954.          '       LVColumnHeaders
  955.                 Set Archive = New cArchive
  956.                 Archive.ArchiveName = Path
  957.                 Archive.ArchiveExt = sExt
  958.                 Archive.GetInfo
  959.          '       LoadCleanup 1
  960.                 Me.Caption = Path
  961.             Case Else
  962.                 SourcePath = QualifyPath(Path)
  963.          '       Tip.MouseNotify TreeView1.hwnd, tipMouseMove
  964.                 LoadFiles (QualifyPath(Path))
  965.         End Select
  966. End Select
  967. Exit Sub
  968. FolderView1_NodeClick_Err:
  969. Screen.MousePointer = vbDefault
  970. Select Case ErrMsgBox("FolderviewDemo.frmFolderviewDemo.FolderView1_NodeClick")
  971.     Case vbAbort
  972.         Exit Sub
  973.     Case vbRetry
  974.         Resume
  975.     Case vbIgnore
  976.         Resume Next
  977. End Select
  978. End Sub
  979.